package service;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class IOService {
    static final String FileName = "/Users/sunqiwei/test.txt";

    public void write(String content) {
        try {
            FileWriter fw = new FileWriter(FileName, true);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.newLine();
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public List<String> read() {
        List<String> all = new ArrayList<>();
        try {
            FileReader fr = new FileReader(FileName);
            BufferedReader br = new BufferedReader(fr);
            String line = br.readLine();
            while (null != line) {
                all.add(line);
                line = br.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return all;
    }
}
